package helpers;

import java.util.Collections;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;

public class GeneralHelper {
	private static Cache cache;
	private static Objectify ofy;

	static
	{
		try {
			cache = CacheManager.getInstance().getCacheFactory()
					.createCache(Collections.emptyMap());
		} catch (CacheException e) {
			// e.printStackTrace();
		}
	
		ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
		ofy = ObjectifyService.begin(opts);
		
	}
	
	public static  Cache getCache()
	{
		if (cache == null) {
			try {
				cache = CacheManager.getInstance().getCacheFactory()
						.createCache(Collections.emptyMap());
			} catch (CacheException e) {
				// e.printStackTrace();
			}
		}
		return cache;
	}
	
	public static  Objectify getObjectify()
	{
		if (ofy == null) {
			ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
			ofy = ObjectifyService.begin(opts);
		}
		return ofy;
	}
}
